package com.humble.humbleojquestionservice.MqProducer;

import com.humble.humbleojcommon.common.ErrorCode;
import com.humble.humbleojcommon.exception.BusinessException;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class QuestionMessageProducer {
    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendMessage(String queueName, String routingKey, String message) {
        try {
            rabbitTemplate.convertAndSend(queueName, routingKey, message);
        } catch (AmqpException e) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR,"消息队列转发异常");
        }
    }
}
